﻿using System.Collections.Generic;
using System.Data.SqlClient;

namespace QuanLyShopThoiTrang_DAO
{
    public class LoaiSanPhamDAO
    {
        public static List<LoaiSanPhamDTO> LoaiSanPham_LayDS()
        {
            List<LoaiSanPhamDTO> dsLoaiSanPham = new List<LoaiSanPhamDTO>();
            DataProvider kn = DataProvider.Instance();
            try
            {
                string sql = "Select * from LoaiSanPham where LoaiSanPham_TrangThai = 'Su dung'";
                DataProvider.OpenConnection();
                SqlCommand com = kn.Connection.CreateCommand();
                com.CommandText = sql;
                SqlDataReader reader = com.ExecuteReader();
                while (reader.Read())
                {
                    switch(reader[1] as string)
                    {
                        case "Áo" :
                            LoaiSanPhamDTO_Ao sp_ao = new LoaiSanPhamDTO_Ao();
                            sp_ao.MaLoaiSanPham = (int)reader[0];
                            dsLoaiSanPham.Add(sp_ao);
                            break;
                        case "Quần" :
                            LoaiSanPhamDTO_Quan sp_quan = new LoaiSanPhamDTO_Quan();
                            sp_quan.MaLoaiSanPham = (int)reader[0];
                            dsLoaiSanPham.Add(sp_quan);
                            break;
                    }
                }
            }
            catch
            {
                dsLoaiSanPham = new List<LoaiSanPhamDTO>();
            }
            finally
            {
                DataProvider.CloseConnection();
            }
            return dsLoaiSanPham;
        }
    }
}
